class MyValue{
public int val;
}

public class Test {
    public static void swap2(MyValue myv1,MyValue myv2){
       int temp = myv1.val;
       myv1.val = myv2.val;
       myv2.val = temp;
    }
    //只交换形参的值，实参未发生改变
    public static void swap(int x,int y){
         int temp = x;
         x = y;
         y = temp;
    }

    public static void main(String[] args) {
        int a = 10;
        int b = 20;
        System.out.println("交换前："+a+" "+b);
        swap(a,b);
        System.out.println("交换后："+a+" "+b);

        MyValue myv1 = new MyValue();
        MyValue myv2 = new MyValue();
        myv1.val = 10;
        myv2.val = 20;
        System.out.println("交换前："+myv1.val+" "+myv2.val);
        swap2(myv1,myv2);
        System.out.println("交换后："+myv1.val+" "+myv2.val);
    }
}
